package com.infoguia.util;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.activation.DataHandler;

public class SendMail {

	final String USER = "";
	final String PASS = "";
	String[] mails;
	Session session;

	public SendMail() {}

	public void exec(String to, String subject, String Text) {

		Properties props;

		try {

			props = new Properties();

			props.put("mail.smtp.host","smtp.gmail.com");
			props.put("mail.smtp.socketFactory.port", "465");
			props.put("mail.smtp.socketFactory.class",
					"javax.net.ssl.SSLSocketFactory");
			props.put("mail.smtp.auth", "true");
			props.put("mail.smtp.port", "465");

			session = Session.getInstance(props,
					new javax.mail.Authenticator() {
						protected PasswordAuthentication getPasswordAuthentication() {
							return new PasswordAuthentication(USER, PASS);
						}
					});

			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress("infoguia@gmail.com"));
			message.setRecipients(Message.RecipientType.TO,
					InternetAddress.parse(to));
			message.setSubject(subject);
			message.setText(Text);

			Transport.send(message);

		}catch (Exception e) {
			System.err.println(e);
		}
	}

}
